home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12683 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  57 lines

  1. Path: alpha2.csd.uwm.edu!peterk
  2. From: peterk@alpha2.csd.uwm.edu (Peter J Kleczka)
  3. Newsgroups: comp.lang.c
  4. Subject: Weird Results with this code :(
  5. Date: 2 Apr 1996 06:48:22 GMT
  6. Organization: Information & Media Technologies, University of Wisconsin - Milwaukee
  7. Distribution: world
  8. Message-ID: <4jqijm$jpk@uwm.edu>
  9. NNTP-Posting-Host: 129.89.169.2
  10.  
  11.  
  12. Hello
  13.     I am trying to learn C and ran into a little snag.  
  14. I got this "timer/eraser" fragment of code from the book
  15. "The Beginners Guide to C" which so far is proving to be
  16. a very good text.  I re-wrote just that part of the code
  17. that doesn't work rather than repost the code from the
  18. book since that would be naughty of me and might get
  19. me into copyright-infringement-type-littigation :)
  20.  
  21. The program is supposed to display
  22. some digits leave them on the screen for a second or so
  23. and then erase them.  The "bug" is that the program seems
  24. to jump to the timer-loop BEFORE it prints out the digits.
  25. Consequently the desired display/delay/erase sequence works
  26. in the wrong order: delay/display/erase.  
  27.  
  28. thanks in advance for your suggestions
  29. please respond via email: peterk@csd.uwm.edu
  30.  
  31.  
  32. /* Display and Erase */
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <time.h>
  36.  
  37. void main()
  38. {
  39.   long now;
  40.   char pause;
  41.  
  42.   now = clock();
  43.   printf ("watch the screen carefully please \n");
  44.   printf("I will print the message: \"123 disappear\"\n");
  45.   printf("then after a short pause\n");
  46.   printf("only the digits \"123\" will disappear\n");
  47.   printf("press return when ready\n");
  48.   scanf ("%c", &pause);
  49.   printf ("123 disappear");
  50.  
  51.   for ( ; clock() - now < CLOCKS_PER_SEC ; );  /* the timer loop */
  52.  
  53.   printf ("\r");
  54.   printf ("   ");
  55.   
  56. }
  57.